package cn.dg.manager.user.address.dao.impl;

import java.util.List;
import java.util.Map;

import org.springframework.stereotype.Repository;

import cn.dg.manager.common.dao.impl.BaseDaoImpl;
import cn.dg.manager.common.entity.PageEntity;
import cn.dg.manager.user.address.dao.UserAddressDao;
import cn.dg.manager.user.address.entity.UserAddressInfoVO;

@Repository("userAddressDao")
public class UserAddressDaoImpl extends BaseDaoImpl implements UserAddressDao {
	
	public static final String USER_ADDRESS_SQL_PACKAGE = UserAddressDao.class.getName().concat(".");
	
	/**
	 * 
	 */
	public PageEntity<UserAddressInfoVO> findUserAddressListPage(Map<String, Object> params) {
		PageEntity<UserAddressInfoVO> page = new PageEntity<UserAddressInfoVO>();
		int pg = params.get("page") != null ? Integer.parseInt(String.valueOf(params.get("page"))) : START_PAGE_INDEX;
		page.setPageNo(pg);
		page.setParams(params);
		int i = params.get("rows") != null ? Integer.parseInt(String.valueOf(params.get("rows"))) : END_PAGE_INDEX;
		page.setPageSize(i);
		page.setParams(params);
		List<UserAddressInfoVO> goodsTypeList = this.sqlSessionTemplate.selectList(USER_ADDRESS_SQL_PACKAGE.concat("findUserAddressListPage"), page);
		page.setResults(goodsTypeList);
		return page;
	}

	public long insertUserAddressInfo(UserAddressInfoVO bean) {
		return (long) this.sqlSessionTemplate.insert(USER_ADDRESS_SQL_PACKAGE.concat("insertUserAddressInfo"), bean);
	}

	public long deleteUserAddress(List<String> asList) {
		return (long) this.sqlSessionTemplate.delete(USER_ADDRESS_SQL_PACKAGE.concat("deleteUserAddress"), asList);
	}

	public long updateUserAddressInfo(UserAddressInfoVO bean) {
		return (long) this.sqlSessionTemplate.update(USER_ADDRESS_SQL_PACKAGE.concat("updateUserAddressInfo"), bean);
	}

	/**
	 *  按条件查找地址
	 */
	public long findUserAddressByCond(Map<String, Object> params) {
		 Object object = this.sqlSessionTemplate.selectOne(USER_ADDRESS_SQL_PACKAGE.concat("findUserAddressByCond"), params);
		 return Long.parseLong(object.toString());
	}
}
